/**
 * Copyright 2011 the original author or authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package it.av.spring.security.page;

import it.av.spring.security.SecurityContextHelper;
import it.av.spring.security.UserDetailsImpl;

import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.resources.CompressedResourceReference;

/**
 * Home Page
 * 
 * @author <a href='mailto:a.vincelli@gmail.com'>Alessandro Vincelli</a>
 * 
 */
public class HomePage extends WebPage {

    private static final CompressedResourceReference STYLES_JQUERY_CSS = new CompressedResourceReference(HomePage.class,
            "resources/jquery.css");

    /**
     * Constructor
     */
    public HomePage() {

        add(CSSPackageResource.getHeaderContribution(STYLES_JQUERY_CSS));
        UserDetailsImpl authenticatedUser = SecurityContextHelper.getAuthenticatedUser();

        if (SecurityContextHelper.isAuthenticatedUser()) {
            add(new Label("firstName", authenticatedUser.getFirstName()));
            add(new Label("lastName", authenticatedUser.getLastName()));
        } else {
            add(new Label("firstName", "").setVisible(false));
            add(new Label("lastName", ""));
        }

        add(new BookmarkablePageLink<String>("login", SignIn.class) {
            @Override
            protected void onBeforeRender() {
                super.onBeforeRender();
                setVisible(!SecurityContextHelper.isAuthenticatedUser());
            }
        });

        add(new BookmarkablePageLink<String>("protectedPage", ProtectedPage.class));

    }

}